<%@page contentType="text/html" import="java.util.Collection, Bean.*"%>
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%
if(session.getAttribute("un")==null){
    response.sendRedirect("indexAdmin.jsp?page=Admin&url=Login");
    out.println("You must be login..!");
}else{%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<script language="javascript" type="text/javascript" src="../script/validate.js"></script>
<script language="javascript">
    function kiemtra(){
        var id = document.form1.txtscheid;
        var name = document.form1.txtschename;
        var fee = document.form1.txtfee;
        var sdate = document.form1.txtstartdate;
        var edate = document.form1.txtenddate;
        var datexame = document.form1.txtdateexam;
        if( laChuoiRong(id.value) )
	{
            alert('Schedule ID is not blank !');
            id.focus();
            return false;
	}
        if( laChuoiRong(name.value) )
	{
            alert('Schedule name is not blank !');
            name.focus();
            return false;
	}
        if( laChuoiRong(fee.value) )
	{
            alert('Fee is not blank !');
            fee.focus();
            return false;
	}
        if( laChuoiRong(sdate.value) )
	{
            alert('StartDate is not blank !');
            sdate.focus();
            return false;
	}
        if( laChuoiRong(edate.value) )
	{
            alert('EndDate is not blank !');
            edate.focus();
            return false;
	}
        if( laChuoiRong(datexame.value) )
	{
            alert('Date exame is not blank !');
            datexame.focus();
            return false;
	}
        if(!laNgay(sdate.value))
            {
                alert('Date invail !');
                sdate.focus();
                return false;
            }
        if(!laNgay(edate.value))
            {
                alert('Date invail !');
                edate.focus();
                return false;
            }
        if(!laNgay(datexame.value))
            {
                alert('Date invail !');
                datexame.focus();
                return false;
            }
        if(!laSoNguyen(fee.value))
            {
                alert('Fee is number!');
                fee.focus();
                return false;
            } 
    }
</script>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <% 
        String scheid="";
        String subid="";
        String schename="";
        String fee="";
        String startdate="";
        String enddate="";
        String dateexam="";
        if(session.getAttribute("scheid")!=null){
            scheid=session.getAttribute("scheid").toString();
            //subid=session.getAttribute("subid").toString();
            schename=session.getAttribute("schename").toString();
            fee=session.getAttribute("fee").toString();
            startdate=session.getAttribute("startdate").toString();
            enddate=session.getAttribute("enddate").toString();
            dateexam=session.getAttribute("dateexam").toString();
        }
        %>
        <% 
        SchedulesBean obj=new SchedulesBean();
        Collection kq=obj.getListSchedules();
        request.setAttribute("st", kq);
        %>
        <%
        SubjectBean subject=new SubjectBean();
        Collection kq1=subject.getListSubject();
        request.setAttribute("st1", kq1);
        %>
        <form method="Post" action="../ControllSchedules" name="form1" onsubmit="return kiemtra()">
            <h3 align="center"l>Schedules Management</h3>
            <table border="0">

                <tr>
                    <td>Schedules ID</td>
                    <td><input type="text" name="txtscheid" value="<%=scheid%>" /><input type="hidden" name="txtup" value="<%=scheid%>" /></td>
                </tr>
                <tr>
                    <td>Subject ID</td>
                    <td><select name="ddlsubid">
                            <c:forEach items="${st1}" var="s">
                                <option>${s.subID}</option>    
                            </c:forEach>
                            
                    </select></td>
                </tr>
                <tr>
                    <td>ScheName</td>
                    <td><input type="text" name="txtschename" value="<%=schename%>" /></td>
                </tr>
                <tr>
                    <td>Fee</td>
                    <td><input type="text" name="txtfee" value="<%=fee%>" /></td>
                </tr>
                <tr>
                    <td>Start Date</td>
                    <td><input type="text" name="txtstartdate" value="<%=startdate%>" /></td>
                </tr>
                
                <tr>
                    <td>End Date</td>
                    <td><input type="text" name="txtenddate" value="<%=enddate%>" /></td>
                </tr>
                <tr>
                    <td>Date Exam</td>
                    <td><input type="text" name="txtdateexam" value="<%=dateexam%>" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" value="Insert" name="bt" />
                        <input type="submit" value="Update" name="bt" />
                        <input type="button" value="Reset" name="bt"  onclick="clear_fields()" />
                    </td>
                </tr>
            </table>
            
            <table border="1">
                <tr>
                    <th>Schedules ID</th>
                    <th>Subject ID</th>
                    <th>ScheName</th>
                    <th>Start Date</th>
                    <th>End Date</th>
                    <th>Date Exam</th>
                    <th>Fee</th>
                    <th colspan="2">Action</th>
                </tr>
                <pg:paging pageSize="10" url="indexAdmin.jsp?page=Admin&url=user">
                    <c:forEach items="${st}" var="s">
                        <pg:item> 
                            <tr>
                                <td><c:out value="${s.scheid}" /></td>
                                <td>${s.subid}</td>
                                <td>${s.schename}</td>
                                
                                <td>${s.startdate}</td>
                                <td>${s.enddate}</td>
                                <td>${s.dateexam}</td>
                                <td>${s.fee}</td>
                                
                                <c:url var="delete" value="../ControllSchedules">
                                    <c:param name="bt" value="Delete" />
                                    <c:param name="scheid" value="${s.scheid}" />
                                    <c:param name="p" value="${param.pageNum}"/>
                                </c:url>
                                <c:url var="edit" value="../ControllSchedules">
                                    <c:param name="bt" value="Edit" />
                                    <c:param name="scheid" value="${s.scheid}" />
                                    <c:param name="subid" value="${s.subid}" />
                                    <c:param name="schename" value="${s.schename}" />
                                    <c:param name="fee" value="${s.fee}" />
                                    <c:param name="startdate" value="${s.startdate}" />
                                    <c:param name="enddate" value="${s.enddate}" />
                                    <c:param name="dateexam" value="${s.dateexam}" />
                                    <c:param name="p" value="${param.pageNum}"/>
                                </c:url>
                                
                                <td><a href="${edit}">Edit</a></td>
                                <td><a href="${delete}" onclick="return confirm('Do you really want to delete these records ?')">Delete</a></td>
                                
                            </tr>
                        </pg:item>
                    </c:forEach>
                    <pg:index>
                        <pg:page><%=thisPage%></pg:page>
                        <pg:firstPage>[First]</pg:firstPage>
                        <pg:lastPage>[Last]</pg:lastPage> 
                    </pg:index> 
                </pg:paging>
            </table>
        </form>
    </body>
</html>
<%}%>